import data from '@/js/data'
import axios from 'axios';

/***************用户****************/
export function loginRequest(func,phoneNumber,password) {
    axios.post(data.getRequestPath()+"/UserController/getUserByIdByPass",null,{
        params:{
            userId:phoneNumber,
            password:password
        }
    }).then((respon)=>{
        func(respon)
    }).catch((error)=>{
        console.log(error)
    })
}

export function registerRequest(func,userId,password,userName,userSex){
    axios.post(data.getRequestPath()+"/UserController/saveUser",null,{
        params:{
            userId:userId,
            password:password,
            userName:userName,
            userSex:userSex
        }
    }).then((respon)=>{
        func(respon)
    }).catch((error)=>{
        console.log(error)
    })
}

export function getUserInfoRequest(func){
    axios.post(data.getRequestPath()+"/UserController/getUserById",null,{
        params:{
            
        },
        headers:{
            Authorization:data.getCache("Authorization")
        }
    }).then((respon)=>{
        func(respon)
    }).catch((error)=>{
        console.log(error)
    })
}

/***************订单****************/
export function getOrderListRequest(func) {
    axios.post(data.getRequestPath()+"/OrdersController/listOrdersByUserId",null,{
        params:{
            
        },
        headers:{
            Authorization:data.getCache("Authorization")
        }
    }).then((respon)=>{
        func(respon)
    }).catch((error)=>{
        console.log(error)
    })
}
export function getOrderRequest(func,orderId) {
    axios.post(data.getRequestPath()+"/OrdersController/getOrdersById",null,{
        params:{
            orderId:orderId
        },
        headers:{
            Authorization:data.getCache("Authorization")
        }
    }).then((respon)=>{
        func(respon)
    }).catch((error)=>{
        console.log(error)
    })
}
export function createOrderRequest(func,businessId,addressId,orderTotal,) {
    axios.post(data.getRequestPath()+"/OrdersController/createOrders",null,{
        params:{
            businessId:businessId,
            daId:addressId,
            orderTotal:orderTotal,
        },
        headers:{
            Authorization:data.getCache("Authorization")
        }
    }).then((respon)=>{
        func(respon)
    }).catch((error)=>{
        console.log(error)
    })
}
export function payOrderRequest(func,orderId) {
    axios.post(data.getRequestPath()+"/OrdersController/payOrder",null,{
        params:{
            orderId:orderId
        },
        headers:{
            Authorization:data.getCache("Authorization")
        }
    }).then((respon)=>{
        func(respon)
    }).catch((error)=>{
        console.log(error)
    })
}

/***************商家****************/
export function getBussinessListRequest(func,type) {
    axios.post(data.getRequestPath()+"/BusinessController/listBusinessByOrderTypeId",null,{
        params:{
            orderTypeId:type
        },
        
    }).then((respon)=>{
        func(respon)
    }).catch((error)=>{
        console.log(error)
    })
}
export function getBussinessRequest(func,businessId) {
    axios.post(data.getRequestPath()+"/BusinessController/getBusinessById",null,{
        params:{
            businessId:businessId
        },
        
    }).then((respon)=>{
        func(respon)
    }).catch((error)=>{
        console.log(error)
    })
}

/***************食物****************/
export function getFoodListRequest(func,businessId) {
    axios.post(data.getRequestPath()+"/FoodController/listFoodByBusinessId",null,{
        params:{
            businessId:businessId
        },
        
    }).then((respon)=>{
        func(respon)
    }).catch((error)=>{
        console.log(error)
    })
}
/***************地址****************/
export function addDeliveryAddressRequest(func,contactName,address,contactTel,contactSex) {
    axios.post(data.getRequestPath()+"/DeliveryAddressController/saveDeliveryAddress",null,{
        params:{
            contactName:contactName,
            address:address,
            contactTel:contactTel,
            contactSex:contactSex
        },
        headers:{
            Authorization:data.getCache("Authorization")
        }
    }).then((respon)=>{
        func(respon)
    }).catch((error)=>{
        console.log(error)
    })
}
export function updatDeliveryAddressRequest(func,addressId,contactName,address,contactTel,contactSex) {
    axios.post(data.getRequestPath()+"/DeliveryAddressController/updateDeliveryAddress",null,{
        params:{
            contactName:contactName,
            address:address,
            contactTel:contactTel,
            contactSex:contactSex,
            daId:addressId
        },
        headers:{
            Authorization:data.getCache("Authorization")
        }
    }).then((respon)=>{
        func(respon)
    }).catch((error)=>{
        console.log(error)
    })
}
export function getDeliveryAddressListRequest(func) {
    axios.post(data.getRequestPath()+"/DeliveryAddressController/listDeliveryAddressByUserId",null,{
        params:{
            
        },
        headers:{
            Authorization:data.getCache("Authorization")
        }
    }).then((respon)=>{
        func(respon)
    }).catch((error)=>{
        console.log(error)
    })
}

export function getDeliveryAddressRequest(func,addressId) {
    axios.post(data.getRequestPath()+"/DeliveryAddressController/getDeliveryAddressById",null,{
        params:{
            daId:addressId
        },
        headers:{
            Authorization:data.getCache("Authorization")
        }
    }).then((respon)=>{
        func(respon)
    }).catch((error)=>{
        console.log(error)
    })
}
export function removeDeliveryAddressRequest(func,addressId) {
    axios.post(data.getRequestPath()+"/DeliveryAddressController/removeDeliveryAddress",null,{
        params:{
            daId:addressId
        },
        headers:{
            Authorization:data.getCache("Authorization")
        }
    }).then((respon)=>{
        func(respon)
    }).catch((error)=>{
        console.log(error)
    })
}
/***************积分****************/
export function getPointListRequest(func) {
    axios.post(data.getRequestPath()+"/PointsController/listPointsByUserId",null,{
        params:{
            
        },
        headers:{
            Authorization:data.getCache("Authorization")
        }
    }).then((respon)=>{
        func(respon)
    }).catch((error)=>{
        console.log(error)
    })
}

/***************购物车****************/
export function getCartRequest(func,businessId) {
    axios.post(data.getRequestPath()+"/CartController/listCart",null,{
        params:{
            businessId:businessId
        },
        headers:{
            Authorization:data.getCache("Authorization")
        }
    }).then((respon)=>{
        func(respon)
    }).catch((error)=>{
        console.log(error)
    })
}
export function addFood8CartRequest(func,businessId,foodId) {
    axios.post(data.getRequestPath()+"/CartController/addCart",null,{
        params:{
            businessId:businessId,
            foodId:foodId
        },
        headers:{
            Authorization:data.getCache("Authorization")
        }
    }).then((respon)=>{
        func(respon)
    }).catch((error)=>{
        console.log(error)
    })
}
export function subFood8CartRequest(func,businessId,foodId) {
    axios.post(data.getRequestPath()+"/CartController/subCart",null,{
        params:{
            businessId:businessId,
            foodId:foodId
        },
        headers:{
            Authorization:data.getCache("Authorization")
        }
    }).then((respon)=>{
        func(respon)
    }).catch((error)=>{
        console.log(error)
    })
}
/***************超级会员****************/
export function apply4MembershipRequset(func){
    axios.post(data.getRequestPath()+"/SuperMemberController/openMembershipByUserId",null,{
        params:{},
        headers:{
            Authorization:data.getCache("Authorization")
        }
    }).then((respon)=>{
        func(respon)
    }).catch((error)=>{
        console.log(error)
    })
}

export function checkVIPRequest(func){
    axios.post(data.getRequestPath()+"/SuperMemberController/checkVIPByUserId",null,{
        params:{
            
        },
        headers:{
            Authorization:data.getCache("Authorization")
        }
    }).then((respon)=>{
        func(respon)
    }).catch((error)=>{
        console.log(error)
    })
}

/***************AI****************/
export function sendMessage2AI(func,msg){
    axios.post(data.getRequestPath()+"/CustomerService/chat",null,{
        params:{
            statement:msg
        },
        headers:{
            Authorization:data.getCache("Authorization")
        }
    }).then((respon)=>{
        func(respon)
    }).catch((error)=>{
        console.log(error)
    })
}